/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.henghai.zhenxuan.ui.bind;

import static com.henghai.zhenxuan.ui.view.StepModel.STATE_DEFAULT;
import static com.henghai.zhenxuan.ui.view.StepModel.STATE_PROCESSING;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.widget.NestedScrollView;
import androidx.databinding.BindingAdapter;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.henghai.zhenxuan.data.bean.MyTeamBean;
import com.henghai.zhenxuan.data.bean.OrderInfoBean;
import com.henghai.zhenxuan.data.bean.ProductInfoBean;
import com.henghai.zhenxuan.data.bean.WinnerBean;
import com.henghai.zhenxuan.data.config.Const;
import com.henghai.zhenxuan.ui.page.BaseWebActivity;
import com.henghai.zhenxuan.data.bean.AppListTypeBean;
import com.henghai.zhenxuan.data.bean.LotteryBean;
import com.henghai.zhenxuan.data.bean.NoticeBean;
import com.henghai.zhenxuan.ui.page.mall.MallListFragment;
import com.henghai.zhenxuan.ui.view.SimpleDividerItemDecoration;
import com.henghai.zhenxuan.ui.view.StepModel;
import com.henghai.zhenxuan.ui.view.VerticalStepView;
import com.henghai.zhenxuan.ui.view.list.FullyGridLayoutManager;
import com.henghai.zhenxuan.ui.view.nine.LotteryView;
import com.henghai.zhenxuan.utils.HiRes;
import com.henghai.zhenxuan.utils.Utils;
import com.blankj.utilcode.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.haibin.calendarview.CalendarView;
import com.henghai.zhenxuan.R;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.kunminx.architecture.utils.ClickUtils;
import com.kunminx.architecture.utils.Res;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.luck.picture.lib.utils.DensityUtil;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnBannerListener;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import cn.jzvd.JzvdStd;

/**
 * Create by KunMinX at 19/9/18
 */
public class CommonBindingAdapter {

    //加载圆角图片
    @BindingAdapter(value = {"imageUrl", "placeHolder"}, requireAll = false)
    public static void imageUrl(ImageView view, String url, Drawable placeHolder) {
        if (url != null && !url.isEmpty()) {
            if (!url.contains("http")) {
                url = Const.URL_IMAGE + url.replace("/profile","");
            }
            Log.d("CommonBindingAdapter", "imageUrl: "+url);
            RequestOptions requestOptions = new RequestOptions().transform(new RoundedCorners(20));
            Glide.with(view.getContext()).load(url).placeholder(Res.getDrawable(R.mipmap.app_logo)).apply(requestOptions).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
        }
    }

    //加载圆角图片
    @BindingAdapter(value = {"imageUrlNodisk", "placeHolder"}, requireAll = false)
    public static void imageUrlNodisk(ImageView view, String url, Drawable placeHolder) {
        if (url != null && !url.isEmpty()) {
            if (!url.contains("http")) {
                url = Const.URL_IMAGE + url.replace("/profile","");
            }
            RequestOptions requestOptions = new RequestOptions().transform(new RoundedCorners(20));
            Glide.with(view.getContext()).load(url).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(Res.getDrawable(R.mipmap.app_logo)).apply(requestOptions).into(view);
        }
    }

    //加载直角图片
    @BindingAdapter(value = {"imageUrlsquare", "placeHolder"}, requireAll = false)
    public static void imageUrlsquare(ImageView view, String url, Drawable placeHolder) {
        if (url != null && !url.isEmpty()) {
            if (!url.contains("http")) {
                url = Const.URL_IMAGE + url.replace("/profile","");
            }
            Glide.with(view.getContext()).load(url).placeholder(Res.getDrawable(R.drawable.ic_def)).diskCacheStrategy(DiskCacheStrategy.ALL).into(view);
        }
    }


    @BindingAdapter(value = {"maskPhone"}, requireAll = false)
    public static void maskPhone(TextView view, MyTeamBean bean) {
        view.setText(Utils.maskPhone(bean.getPhonenumber()));
    }


    @BindingAdapter(value = {"maskUserName"}, requireAll = false)
    public static void maskUserName(TextView view, MyTeamBean bean) {
        if (bean != null
                && bean.getPhonenumber() != null
                && bean.getNickName() != null
                && bean.getPhonenumber().equals(bean.getNickName())) {
            view.setText(Utils.maskPhone(bean.getNickName()));
        }
    }


    @BindingAdapter(value = {"visible"}, requireAll = false)
    public static void visible(View view, boolean visible) {
        if (visible && view.getVisibility() == View.GONE) {
            view.setVisibility(View.VISIBLE);
        } else if (!visible && view.getVisibility() == View.VISIBLE) {
            view.setVisibility(View.GONE);
        }
    }


    @BindingAdapter(value = {"videoPlayer"}, requireAll = false)
    public static void setVideoPlayer(JzvdStd videoView, String url) {
        if (url == null || url.isEmpty()) {
            return;
        }
        videoView.setUp(Const.URL_IMAGE + url.replace("/profile",""), "视频教程");
//        videoView.posterImageView.setImage("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");
    }

    @BindingAdapter(value = {"taskAdd"}, requireAll = false)
    public static void setTaskAdd(AppCompatTextView textViewCompat, String str) {
        str = Utils.stripUnit(str);
        if (str.isEmpty()) {
            return;
        }
        textViewCompat.setText(str);
    }


    @BindingAdapter(value = {"winnerText"}, requireAll = false)
    public static void setWinnerText(AppCompatTextView textViewCompat, WinnerBean.RowsBean bean) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dateFormat.parse(bean.getCreateTime()));
            int month = calendar.get(Calendar.MONTH) + 1; // Calendar.MONTH 是从 0 开始的
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            textViewCompat.setText("恭喜 " + bean.getUserName() + " " + month + "-" + day + " " + "抽中 " + bean.getProductName());
        } catch (Exception e) {
            e.printStackTrace();
            textViewCompat.setText("恭喜 " + bean.getUserName() + " " + bean.getCreateTime() + " " + "抽中 " + bean.getProductName());
        }

    }


    @BindingAdapter(value = {"orderText"}, requireAll = false)
    public static void setOrderText(AppCompatTextView textViewCompat, String text) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dateFormat.parse(text));
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH) + 1; // Calendar.MONTH 是从 0 开始的
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            textViewCompat.setText(year + "." + month + "." + day);
        } catch (Exception e) {
            e.printStackTrace();
            textViewCompat.setText(text);
        }

    }

    @BindingAdapter(value = {"integralText"}, requireAll = false)
    public static void setIntegralText(AppCompatTextView textViewCompat, String str) {
        if (str.isEmpty()) {
            return;
        }
        if (Integer.parseInt(str) > 0) {
            textViewCompat.setTextColor(HiRes.INSTANCE.getColor(R.color.color_dd2));
            textViewCompat.setText("+" + str);
        } else {
            textViewCompat.setTextColor(HiRes.INSTANCE.getColor(R.color.color_298));
            textViewCompat.setText(str);
        }
    }

    @BindingAdapter(value = {"invisible"}, requireAll = false)
    public static void invisible(View view, boolean visible) {
        if (visible && view.getVisibility() == View.INVISIBLE) {
            view.setVisibility(View.VISIBLE);
        } else if (!visible && view.getVisibility() == View.VISIBLE) {
            view.setVisibility(View.INVISIBLE);
        }
    }

    @BindingAdapter(value = {"size"}, requireAll = false)
    public static void size(View view, Pair<Integer, Integer> size) {
        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
        params.width = size.first;
        params.height = size.second;
        view.setLayoutParams(params);
    }

    @BindingAdapter(value = {"transX"}, requireAll = false)
    public static void translationX(View view, float translationX) {
        view.setTranslationX(translationX);
    }

    @BindingAdapter(value = {"transY"}, requireAll = false)
    public static void translationY(View view, float translationY) {
        view.setTranslationY(translationY);
    }

    @BindingAdapter(value = {"x"}, requireAll = false)
    public static void x(View view, float x) {
        view.setX(x);
    }

    @BindingAdapter(value = {"y"}, requireAll = false)
    public static void y(View view, float y) {
        view.setY(y);
    }

    @BindingAdapter(value = {"alpha"}, requireAll = false)
    public static void alpha(View view, float alpha) {
        view.setAlpha(alpha);
    }

    @BindingAdapter(value = {"textColor"}, requireAll = false)
    public static void setTextColor(TextView textView, int textColorRes) {
        textView.setTextColor(textView.getContext().getColor(textColorRes));
    }

    @BindingAdapter(value = {"selected"}, requireAll = false)
    public static void selected(View view, boolean select) {
        view.setSelected(select);
    }

    @BindingAdapter(value = {"mAdapter"}, requireAll = false)
    public static void setAdapter(RecyclerView recyclerView, RecyclerView.Adapter adapter) {
        recyclerView.setNestedScrollingEnabled(false);
        FullyGridLayoutManager manager = new FullyGridLayoutManager(recyclerView.getContext(),
                2, GridLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);


    }

    @BindingAdapter(value = {"mDecorationAdapter"}, requireAll = false)
    public static void setDecorationAdapter(RecyclerView recyclerView, RecyclerView.Adapter adapter) {
        recyclerView.setAdapter(adapter);
        int dividerThickness = 1;
        recyclerView.addItemDecoration(new SimpleDividerItemDecoration(Color.GRAY, dividerThickness));
    }

    @BindingAdapter(value = {"mStepAdapter"}, requireAll = false)
    public static void setStepAdapter(VerticalStepView stepView, OrderInfoBean list) {
        List<StepModel> data = new ArrayList<>();
        if (list.getShippingRecordList() != null) {
            for (int i = 0; i < list.getShippingRecordList().size(); i++) {

                StepModel step = new StepModel(list.getShippingRecordList().get(i).getContext(), i == 0 ? STATE_DEFAULT : STATE_PROCESSING, list.getShippingRecordList().get(i).getTime());
                data.add(step);
            }
            stepView.setData(data);
        }
    }


    @BindingAdapter(value = {"mImageAdapter"}, requireAll = false)
    public static void setImageAdapter(RecyclerView mRecyclerView, RecyclerView.Adapter mAdapter) {
//        recyclerView.setNestedScrollingEnabled(false);
        FullyGridLayoutManager manager = new FullyGridLayoutManager(mRecyclerView.getContext(),
                4, GridLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(manager);

        RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
        if (itemAnimator != null) {
            ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
        }
        mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(4,
                DensityUtil.dip2px(mRecyclerView.getContext(), 8), false));
        mRecyclerView.setAdapter(mAdapter);
    }

    @BindingAdapter(value = {"mTabAdapter"}, requireAll = false)
    public static void setTabAdapter(TabLayout tabLayout, ArrayList<AppListTypeBean.RowsBean> list) {
//        for (int i = 0; i < list.size(); i++) {
//            tabLayout.addTab(tabLayout.newTab().setText(list.get(i).getDictLabel()));
//        }
    }


    @BindingAdapter(value = {"mPrivacyText"}, requireAll = false)
    public static void setPrivacyText(AppCompatTextView textViewCompat, String content) {

        textViewCompat.setText(Utils.getPrivacyContent(content));
        textViewCompat.setMovementMethod(LinkMovementMethod.getInstance());
    }


    @BindingAdapter(value = {"bindTabMallPage"}, requireAll = false)
    public static void setBindTabMallPage(ViewPager2 viewPager, ArrayList<AppListTypeBean.RowsBean> list) {
        TabLayout tabLayout = (viewPager.getRootView()).findViewById(R.id.mall_product_tye_rv);

        if (list == null || list.isEmpty()) {
            return;
        }
        viewPager.setAdapter(new FragmentStateAdapter((FragmentActivity) viewPager.getContext()) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                return new MallListFragment(list.get(position).getDictValue());
            }

            @Override
            public int getItemCount() {
                return list.size();
            }

        });
        new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(list.get(position).getDictLabel())).attach();
    }

    @BindingAdapter(value = {"bindTabLayoutListener"}, requireAll = false)
    public static void listenTabLayout(TabLayout tabLayout, TabLayout.OnTabSelectedListener listener) {
        tabLayout.addOnTabSelectedListener(listener);
    }


    @BindingAdapter(value = {"mProductAdapter"}, requireAll = false)
    public static void setProductAdapter(Banner banner, List<ProductInfoBean.ProductFileListBean> productInfoBean) {
        banner.setAdapter(new BannerImageAdapter<ProductInfoBean.ProductFileListBean>(productInfoBean) {
            @Override
            public void onBindView(BannerImageHolder holder, ProductInfoBean.ProductFileListBean listBean, int i, int i1) {
                if (listBean.getUrl() != null) {
                    Glide.with(holder.itemView).load(Const.URL_IMAGE + listBean.getUrl().replace("/profile","")).into(holder.imageView);
                }
            }
        }).setIndicator(new CircleIndicator(banner.getContext()));
    }

    @BindingAdapter(value = {"mBannerAdapter"}, requireAll = false)
    public static void setBannerAdapter(Banner banner, ArrayList<NoticeBean.NoticeFileBean> list) {
        banner.setAdapter(new BannerImageAdapter<NoticeBean.NoticeFileBean>(list) {
            @Override
            public void onBindView(BannerImageHolder holder, NoticeBean.NoticeFileBean noticeBean, int i, int i1) {
                Glide.with(holder.itemView).load(Const.URL_IMAGE + noticeBean.getFileUrl().replace("/profile","")).into(holder.imageView);
            }
        }).setIndicator(new CircleIndicator(banner.getContext()));
        banner.setOnBannerListener((OnBannerListener<NoticeBean.NoticeFileBean>) (noticeBean, i) -> {
            if (noticeBean.getFileSuperUrl() != null && !noticeBean.getFileSuperUrl().isEmpty()) {
                BaseWebActivity.show(banner.getContext(), noticeBean.getFileSuperUrl());
            }
        });
    }


    @BindingAdapter(value = {"mLotteryAdapter", "bindLotteryListener"}, requireAll = false)
    public static void listenLottery(LotteryView lotteryView, ArrayList<LotteryBean> list, LotteryView.LotteryListener listener) {
        lotteryView.setDataAndListener(list, listener);
    }


    @BindingAdapter(value = {"prizeCount"}, requireAll = false)
    public static void setPrizeCount(LotteryView lotteryView, String text) {
        if (lotteryView != null && lotteryView.getAdapter() != null) {
            lotteryView.getAdapter().notifyDataSetChanged();
        }
    }

    @BindingAdapter(value = {"prizeType"}, requireAll = false)
    public static void setPrizeType(AppCompatTextView lotteryView, String prizeType) {
        if (prizeType.equals("1")) {
            lotteryView.setVisibility(View.INVISIBLE);
        } else {
            lotteryView.setVisibility(View.VISIBLE);
        }

    }


    @BindingAdapter(value = {"textUnderLine"}, requireAll = false)
    public static void setTextUnderLine(AppCompatTextView textView, String text) {
        if (text != null) {
            SpannableString content = new SpannableString(text);
            content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
            textView.setText(content);
        }
    }

    @BindingAdapter(value = {"imageSize"}, requireAll = false)
    public static void setImageSize(AppCompatImageView imageView, ProductInfoBean.ProductFileListBean bean) {
        if (bean != null && bean.getImageWidth() != null && bean.getImageHeight() != null) {
            ViewGroup.LayoutParams params = imageView.getLayoutParams();
            float aspectRatio = Float.parseFloat(bean.getImageHeight()) / Float.parseFloat(bean.getImageWidth());//计算原始宽高比
            params.width = ScreenUtils.getScreenWidth();//设置固定屏幕宽度
            params.height = (int) (params.width * aspectRatio);//按比例计算高度
            imageView.setLayoutParams(params);
        }
    }

    @BindingAdapter(value = {"textStatus"}, requireAll = false)
    public static void setTextStatus(AppCompatTextView textView, String text) {
        if (text != null) {
            if (text.equals("0")) {
                textView.setText(HiRes.INSTANCE.getString(R.string.unpaid));
            } else {
                textView.setClickable(false);
                textView.setBackgroundColor(HiRes.INSTANCE.getColor(R.color.color_d1d2));
                textView.setText(HiRes.INSTANCE.getString(R.string.paid));
            }
        }
    }


    @BindingAdapter(value = {"calendarAdapter"}, requireAll = false)
    public static void setCalendarAdapter(CalendarView mCalendarView, Map<String, com.haibin.calendarview.Calendar> map) {
        mCalendarView.setSchemeDate(map);
    }


    @BindingAdapter(value = {"bindCalendarListener"}, requireAll = false)
    public static void listenCalendar(CalendarView mCalendarView, CalendarView.OnMonthChangeListener listener) {
        mCalendarView.setOnMonthChangeListener(listener);
    }


    @BindingAdapter(value = {"onClickWithDebouncing"}, requireAll = false)
    public static void onClickWithDebouncing(View view, View.OnClickListener clickListener) {
        ClickUtils.applySingleDebouncing(view, clickListener);
    }


    @BindingAdapter(value = {"taskStatusStr"}, requireAll = false)
    public static void setTaskStatusStr(AppCompatTextView textView, String taskStatus) {
        if (taskStatus != null && !taskStatus.isEmpty()) {
            switch (taskStatus) {
                case "0":
                    textView.setText("接取任务");
                    break;
                case "1":
                    textView.setText("提交任务");
                    break;
                case "2":
                    textView.setText("继续上传");
                    break;
                case "3":
                    textView.setText("审核通过");
                    break;
                case "4":
                    textView.setText("重新上传");
                    break;
            }
        }
    }


    @BindingAdapter(value = {"taskMakeText"}, requireAll = false)
    public static void setTaskMakeText(AppCompatTextView textView, int text) {
        SpannableString spannableString = new SpannableString("已赚: " + text + "人");
        spannableString.setSpan(new ForegroundColorSpan(Color.GRAY), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ForegroundColorSpan(Color.RED), 4, 4 + (String.valueOf(text).length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannableString);
    }

    @BindingAdapter(value = {"taskResidueText"}, requireAll = false)
    public static void setTaskResidueText(AppCompatTextView textView, String text) {

        SpannableString spannableString = new SpannableString("剩余: " + text);
        spannableString.setSpan(new ForegroundColorSpan(Color.GRAY), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannableString);
    }

    @BindingAdapter(value = {"productViewStyle"}, requireAll = false)
    public static void setProductViewStyle(AppCompatTextView textView, boolean isFlag) {
        if (isFlag) {
            textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        }
    }

    @BindingAdapter(value = {"favorableRateText"}, requireAll = false)
    public static void setFavorableRateText(AppCompatTextView textView, String favorableRate) {
        textView.setText("好评率" + favorableRate);
    }

    @BindingAdapter(value = {"loginBrowse"}, requireAll = false)
    public static void setLoginBrowse(AppCompatEditText editText, boolean isBrowse) {
        if (isBrowse) {
            editText.setTransformationMethod(null);
        } else {
            editText.setTransformationMethod(new PasswordTransformationMethod());
        }
        editText.setSelection(editText.getText().length());
    }

    @BindingAdapter(value = {"taskStatusText"}, requireAll = false)
    public static void setTaskState(AppCompatTextView textView, String taskStatus) {
        if (taskStatus != null && !taskStatus.isEmpty()) {
            switch (taskStatus) {
                case "0":
                    textView.setText("未接取");
                    break;
                case "1":
                    textView.setText("待上传");
                    break;
                case "2":
                    textView.setText("待审核");
                    break;
                case "3":
                    textView.setText("审核通过");
                    break;
                case "4":
                    textView.setText("审核未通过");
                    break;
            }
        }
    }

    @BindingAdapter(value = {"refreshListener"}, requireAll = false)
    public static void refreshListener(SmartRefreshLayout view, OnRefreshListener listener) {
        view.setOnRefreshListener(listener);
    }

    @BindingAdapter(value = {"loadListener"}, requireAll = false)
    public static void loadListener(SmartRefreshLayout view, OnLoadMoreListener listener) {
        view.setOnLoadMoreListener(listener);
    }

    @BindingAdapter(value = {"bindScrollViewListener"}, requireAll = false)
    public static void bindScrollViewListener(NestedScrollView nestedScrollView, NestedScrollView.OnScrollChangeListener listener) {
        nestedScrollView.setOnScrollChangeListener(listener);
    }

    static final boolean[] isAnimateIng = new boolean[1];

    @BindingAdapter(value = {"bindTitleBarListener"}, requireAll = false)
    public static void listenTitleBar(TitleBar titleBar, OnTitleBarListener listener) {
        titleBar.setOnTitleBarListener(listener);
    }

    @BindingAdapter(value = {"bindOnKeyListener"}, requireAll = false)
    public static void listenOnKey(EditText editText, View.OnKeyListener listener) {
        editText.setOnKeyListener(listener);
    }


}
